package com.galaxy;

import com.galaxy.util.M;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义异常处理器
 *
 * @author ieflex
 */
@RestControllerAdvice
public class InterfaceExceptionHandler {


	/**
	 * 拦截所有运行时的全局异常
	 */
	@ExceptionHandler(RuntimeException.class)
	@ResponseBody
	public Object runtimeException(RuntimeException e) {
		M err = M.err();
		err.setMsg(e.getMessage());
		return err;
	}

	/**
	 * 系统异常捕获处理
	 */
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public Object exception(Exception e) {
		M err = M.err();
		err.setMsg(e.getMessage());
		return err;
	}
}
